Added ProtocolHelper and some tests
[brmtron.git] / BrmTron Client / src / cz / brmlab / brmtron / client / ConnetionManager.java
blob9a3d4455c86ff17915791d25cc7e10ddaa48c931
1 package cz.brmlab.brmtron.client;
3 import java.io.BufferedReader;
4 import java.io.DataOutputStream;
5 import java.io.InputStreamReader;
6 import java.net.Socket;
7 import java.net.UnknownHostException;
9 import android.util.Log;
11 public class ConnetionManager {
12 private static Socket sock;
13 private static DataOutputStream outStream;
14 private static BufferedReader inStream;
15 static final String LOG_TAG = "BrmTron ConnectionManager";
17 public void ConnectionManager() {
21 public void connect(String host, int port) {
22 try {
23 sock = new Socket(host, port);
24 outStream = new DataOutputStream(sock.getOutputStream());
25 inStream = new BufferedReader(new InputStreamReader(sock.getInputStream()));
26 } catch(UnknownHostException e) {
27 Log.e(LOG_TAG, "Unknown host");
28 } catch(Exception e) {
29 Log.e(LOG_TAG, e.toString());
33 public void disconnect(){
34 try {
35 outStream.close();
36 inStream.close();
37 sock.close();
38 } catch(Exception e) {
39 Log.e(LOG_TAG, e.toString());
43 public DataOutputStream getOutputStream() {
44 return outStream;
47 public BufferedReader getInputReader() {
48 return inStream;